{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### <center> Solving System of Linear Equations using Python (numpy) </center> \n",
    "\n",
    "<center> 1a + 1b = 35 </center> \n",
    "<center> 2a + 4b = 94</center> \n",
    "<p> </p> \n",
    "\n",
    "$$A = \\left[ \\begin{array}{ccc} 1 & 1 \\\\ 2 & 4 \\\\ \\end{array} \\right]$$ \n",
    "<p></p>\n",
    "$$X = \\left[ \\begin{array}{c} a \\\\ b \\\\ \\end{array} \\right]  $$ \n",
    "<p></p>\n",
    "$$B = \\left[ \\begin{array}{c} 35 \\\\ 94 \\\\ \\end{array} \\right]$$\n",
    "<p></p>\n",
    "$$\\left[ \\begin{array}{ccc} 1 & 1 \\\\ 2 & 4 \\\\ \\end{array} \\right]\\left[ \\begin{array}{c} a \\\\ b \\\\ \\end{array} \\right] = \\left[ \\begin{array}{c} 35 \\\\ 94 \\\\ \\end{array} \\right] $$ \n",
    "<p></p>\n",
    "<center> A**X** = B </center>\n",
    "<p> </p>\n",
    "<center> A<sup>-1 </sup>A**X** = A<sup>-1</sup>B  </center>\n",
    "<p> </p>\n",
    "\n",
    "<center>**X** = A<sup>-1</sup>B </center>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 23.]\n",
      " [ 12.]]\n"
     ]
    }
   ],
   "source": [
    "import numpy as np \n",
    "\n",
    "# Defining matrixes\n",
    "A = np.matrix([[1,1], [2,4]])\n",
    "B = np.matrix([[35], [94]])\n",
    "\n",
    "# Taking inverse of A\n",
    "A_inverse = np.linalg.inv(A)\n",
    "\n",
    "# Solving for X\n",
    "X = A_inverse * B \n",
    "print X\n",
    "#http://docs.scipy.org/doc/numpy-1.10.1/reference/routines.linalg.html"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
